package com.zxp.springboot.hello.service.impl;

import com.zxp.springboot.hello.mapper.EmployeeMapper;
import com.zxp.springboot.hello.model.Employee;
import com.zxp.springboot.hello.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zxp
 * @date 2021-08-26 9:48
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;

    /**
     * 如果不开启事务，则不会触发一级缓存
     * @param id
     * @return
     */
    @Override
    @Transactional
    public Employee getById(Long id) {
        // 查询两次，看能否触发一级缓存
        employeeMapper.getById(id);
        return employeeMapper.getById(id);
    }
}
